package pucpr.pibic.funcoes;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class ManipulaArquivo {

	public ArrayList<String> lerArquivo(String arquivo){

		ArrayList<String> linhas = new ArrayList<String>();

		try {
			FileReader file = new FileReader(arquivo);
			BufferedReader bufferedReader = new BufferedReader(file);
			String line = null;
			try {
				bufferedReader.readLine();
				bufferedReader.readLine();
				while((line = bufferedReader.readLine()) != null){
					linhas.add(line);
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return linhas;
	}

	public ArrayList<Row> lerArquivoExcel(String arquivo){
		File file = new File(arquivo);
		FileInputStream fis = null;
		ArrayList<Row> listaRows = new ArrayList<Row>();
		try {
			fis = new FileInputStream(file);
			XSSFWorkbook wb = null;

			wb = new XSSFWorkbook(fis);
			XSSFSheet sh = wb.getSheetAt(0);
			for(int i = 1; i < sh.getLastRowNum(); i++){
				Row row = sh.getRow(i);
				if(row != null)
					listaRows.add(row);
			}
			return listaRows;
		}
		catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
}